﻿
@{
    ViewData["Title"] = "帖子标签管理";
}
@using System.Data;
@model List<Mango.Models.PostsTagsModel>
<table class="table">
    <tbody>
        <tr>
            <td>
                <input type="button" class="btn btn-success" id="btn_Add" value="添加标签" />
            </td>
        </tr>
    </tbody>
</table>
<table class="table  table-sm table-hover table-list table-bordered">
    <thead>
        <tr>
            <th>Id</th>
            <th>标签名称</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach (Mango.Models.PostsTagsModel item in Model)
        {
            <tr>
                <td>
                    @item.TagsId
                </td>
                <td>
                    @item.TagsName
                </td>
                <td>
                    <a href="javascript:EditInfo(@item.TagsId, '@item.TagsName');" class="del">修改</a>
                </td>
            </tr>
        }
    </tbody>
</table>
<script type="text/javascript">
    function EditInfo(tagsId, tagsName) {
        layer.prompt({ formType: 0, value: tagsName, title: '编辑标签', },
            function (value, index, elem) {
                $.ajax({
                    type: 'post',
                    url: '/Posts/EditTags',
                    data: 'tagsName=' + value + '&tagsId=' + tagsId,
                    success: function (res) {
                        if (res) {
                            alert('修改成功');
                            window.location.href = window.location.href;
                        }
                    }
                });
            }
        );
    }
    //
    $("#btn_Add").click(function () {
        layer.prompt({ title: '添加用户组', formType: 0 }, function (text, index) {
            //layer.close(index);
            $.ajax({
                type: 'post',
                url: '/Posts/AddTags',
                data: 'tagsName=' + text,
                success: function (res) {
                    if (res) {
                        alert('添加成功');
                        window.location.href = window.location.href;
                    }
                }
            });
        });
    });
</script>
